<?php
namespace app\console\controller;

use app\console\model\Login as LoginModel;

class Login
{
    public function login()
    {
        return view('login');
    }

    public function loginPost()
    {   
        $data['name'] = trim(input('name'));
        $data['password'] = md5(trim(input('password')));
        $adminInfo = LoginModel::where($data)->find();
        if (!$adminInfo) {
            session('admin_error', '账号或密码错误');
            return redirect('Login/login');
        }
        $adminInfo->update_time = time();
        $adminInfo->save();

        session('adminInfo', $adminInfo);
        session('admin_error', null);
        // set_log(1, '登录系统');
        
        return redirect('Index/index');
    }

    public function logout()
    {
        // set_log(1, '退出登录');
        session('adminInfo', null);
        session('admin_error', null);

        return redirect('Login/login');
    }

    public function lockscreen()
    {
        $name = session('adminInfo')['name'];

        return view('lockscreen', compact('name'));
    }

}
